package cn.foolishbird.basic.step;

import cn.hutool.core.collection.CollUtil;

import java.util.List;

/**
 * 分步执行逻辑
 *
 * @author Eric
 * @version 1.0
 * @date 2019-12-16
 */
public abstract class StepExecute<T> {

    private Step<T> step;

    public StepExecute(Step<T> step) {
        this.step = step;
    }

    public void execute() {
        List<T> data = step.current();
        while (!CollUtil.isEmpty(data)) {
            data.forEach(t -> {
                step.singleExecute(t);
            });
            step.nextStep();
            data = step.current();
        }
    }

}
